<!--督导结果统计-->
<template>
  <div class="wrapper-container">
    <el-form ref="form" class="my-form">
      <el-row class="single-row">
        <el-col :span="24">
          <el-row class="item-row">
            <el-col class="name-col" :span="8"> 指标体系 </el-col>
            <el-col class="content-col" :span="16">
              <el-select
                v-model="system"
                style="width: 40%"
                size="small"
                placeholder="请选择"
              >
                <el-option
                  v-for="item in systemList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </el-col>
          </el-row>
        </el-col>
      </el-row>
    </el-form>

    <div
      class="search-container"
      style="justify-content: flex-start !important"
    >
      <div class="filter-button">
        <el-radio-group v-model="radio4" size="mini">
          <el-radio-button style="padding-right: 10px" label="校区级"
            >校区级</el-radio-button
          >
          <el-radio-button label="系 级">系 级</el-radio-button>
        </el-radio-group>
      </div>
    </div>
    <div class="table-container">
      <el-table
        v-if="!tableChangeFlag"
        :data="tableData"
        :span-method="arraySpanMethod"
        border
        style="width: 100%"
        class="table-data"
        row-class-name="row-class"
        cell-class-name="cell-class"
        header-row-class-name="header-row-class"
        header-cell-class-name="header-cell-class"
      >
        <el-table-column
          prop="role1"
          v-if="radio4 == '校区级'"
          label="角色等级"
          align="center"
        >
        </el-table-column>
        <el-table-column v-else prop="role2" label="角色等级" align="center">
        </el-table-column>
        <el-table-column
          v-if="radio4 == '系 级'"
          prop="roleSystem"
          label="角色等级系"
          align="center"
        >
        </el-table-column>
        <el-table-column prop="roleType" label="角色等级类型" align="center">
        </el-table-column>

        <el-table-column prop="teacher" label="专家姓名" align="center">
        </el-table-column>

        <el-table-column label="操作" align="center">
          <ButtonItem
            style="margin: 0 auto"
            @click=""
            :name="'设置'"
            :link="''"
            :icon="'el-icon-view'"
            :buttonColor="'blue'"
          ></ButtonItem>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import SelectItem from "../../../components/SelectItem.vue";
import InputItem from "../../../components/InputItem.vue";
import ButtonItem from "../../../components/ButtonItem.vue";
export default {
  components: {
    SelectItem,
    InputItem,
    ButtonItem,
  },
  data() {
    return {
      tableChangeFlag: false,
      radio4: "系 级",
      system: "2021教学评价7月",
      systemList: [
        {
          value: "2021教学评价7月",
          label: "2021教学评价7月",
        },
        {
          value: "2021教学评价8月",
          label: "2021教学评价8月",
        },
      ],
      state: "",
      stateList: [
        {
          value: "待提交",
          label: "待提交",
        },
        {
          value: "审批中",
          label: "审批中",
        },
        {
          value: "已审批",
          label: "已审批",
        },
        {
          value: "待审批",
          label: "待审批",
        },
      ],
      spacia: "",
      room: "",
      roomList: [],
      mounth: "12月",
      mounthList: [],
      teacherName: "",
      tableData: [
        {
          role1: "校区级",
          role2: "系级",
          roleSystem: "系1",
          roleType: "组长",
          teacher: "张三(教研室1)",
        },
        {
          role1: "校区级",
          role2: "系级",
          roleSystem: "系1",
          roleType: "副组长",
          teacher: "张三(教研室2)",
        },
        {
          role1: "校区级",
          role2: "系级",
          roleSystem: "系2",
          roleType: "组员",
          teacher: "张三(教研室3)",
        },
      ],
    };
  },
  computed: {
    config() {
      return {
        mergeTarget: "id", // 通用依据
        combineProp: [
          // combineProp - 根据mergeTarge 进行合并的单元格属性
          "role1",
          "role2",
          "roleSystem",
        ],
      };
    },
  },
  watch: {
    radio4(val) {
      var _this = this;
      this.tableChangeFlag = true;
      this.mergeRow();
      window.setTimeout(() => {
        _this.tableChangeFlag = false;
      }, 500);
    },
  },
  methods: {
    arraySpanMethod({ row, column }) {
      const span = column["property"] + "-span";
      if (row[span]) {
        return row[span];
      }
    },
    choiceLink(index) {
      this.record = index;
    },
    checkboxChange(e) {
      console.log(e);
    },

    isEmpty(val) {
      return typeof val == "undefined" || val === null || val == "-";
    },
    isObject(val) {
      return Object.prototype.toString.call(val) === "[object Object]";
    },
    mergeRow() {
      let arr = [].concat(this.tableData);
      // arr.splice(index, 0, Object.assign({}, row))

      this.tableData = this.mergeData(arr);
    },
    mergeData(list) {
      // mergeTarge - 合并项依据
      // combineProp - 根据mergeTarge 进行合并的单元格属性
      return this.filterData(this.config, [].concat(list));
    },
    filterData(config, tableData, targetProp) {
      const { mergeTarget, combineProp } = config;
      // 叠加的合并条件
      combineProp.forEach((column) => {
        // 记录合并项
        let combineCount = 1;
        if (this.isObject(column)) {
          return this.filterData.call(this, column, tableData, mergeTarget);
        }
        // 使用倒序遍历
        for (let i = tableData.length - 1; i >= 0; i--) {
          let curr = tableData[i],
            prev = tableData[i - 1];

          if (this.isEmpty(prev)) {
            // 已经循环完毕
            curr[`${column}-span`] = {
              rowspan: combineCount,
              colspan: combineCount >= 1 ? 1 : 0,
            };
            break;
          }

          if (
            prev[targetProp] === curr[targetProp] &&
            prev[mergeTarget] === curr[mergeTarget] &&
            prev[`${column}`] === curr[`${column}`]
          ) {
            ++combineCount;
            curr[`${column}-span`] = {
              rowspan: 0,
              colspan: 0,
            };
          } else {
            curr[`${column}-span`] = {
              rowspan: combineCount,
              colspan: combineCount >= 1 ? 1 : 0,
            };
            prev[`${column}-span`] = {
              rowspan: 1,
              colspan: 1,
            };
            // 前后项不相符时，对combinecount进行重置
            combineCount = 1;
          }
        }
      });
      return tableData;
    },
  },
  created() {
    this.mergeRow();
  },
  mounted() {
    var _this = this;
    var tempArry = Array.from(new Array(12).keys());
    tempArry.forEach(function (e) {
      _this.mounthList.push({
        value: e + 1,
        label: e + 1 + "月",
      });
    });
  },
};
</script>
<style lang="less" scoped>
.search-container {
  justify-content: flex-start !important;
}

.search-button {
  cursor: pointer;
  box-sizing: border-box;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  width: 70px;
  height: 27px;
  background: #f1f8fe;
  border: 1px solid #51aef6;
  border-radius: 6px;

  > span {
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #51aef6;
  }

  > img {
    width: 19px;
    height: 19px;
    margin-right: 4px;
  }
}

.table-container {
  margin-top: 30px;

  .el-table td,
  .el-table th.is-leaf,
  .el-table--border,
  .el-table--group {
    border-color: #c7d7eb;
  }

  .el-table__header tr,
  .el-table__header th {
    padding: 0;
    height: 76px;
    background-color: #edf2f9;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    line-height: 20px;
    color: #004ca7;
  }

  .el-table__body tr,
  .el-table__body td {
    padding: 0;
    height: 86px;
  }

  .wrapper-button {
    display: flex;
    flex-direction: column;
    align-items: center;

    > div {
      margin-bottom: 8px;
    }
  }
}
</style>

<style lang="less" scoped>
.item-row .el-col {
  display: flex;
  align-items: center;
  min-height: 60px;
  border-right: none !important;
}
.item-row .el-col:not(:first-child) {
  border-left: 1px solid rgba(0, 76, 167, 0.39);
}
.single-row .el-col:not(:last-child) {
  border-right: 1px solid rgba(0, 76, 167, 0.39);
}
.my-form .single-row:not(:last-child) {
  border-bottom: 1px solid rgba(0, 76, 167, 0.39);
}
.name-col {
  justify-content: center;
  font-size: 16px;
  font-weight: bold;
  color: #004ca7;
  background: rgba(77, 129, 192, 0.1);
}
.content-col {
  padding-left: 10%;
}
.wrapper-container {
  .my-form {
    width: 100%;
    border: 1px solid rgba(0, 76, 167, 0.8);
    margin: 57px auto 19px;
    border-radius: 9px;
  }
  .button-group {
    padding-top: 20px;
    width: 915px;
    margin: 0 auto;
    text-align: center;
    > div {
      display: inline-block;
      font-size: 18px;
      padding: 6px 22px;
      border-radius: 6px;
      &:nth-child(1) {
        color: #f3b815;
        border: 1px solid #f3b815;
        background: #fff6ef;
        margin: 0 40px;
      }
    }
  }
}

@import "../../../styles/special.less";
.bottom-block {
  display: flex;
  flex-direction: row;
  justify-content: flex-end;
  .text {
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    line-height: 39px;
    color: #004ca7;
  }
}
.content-div {
  max-width: 200px;
}
.comment-div {
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}
.table-container::v-deep .el-table__header th {
  border-color: #c7d7eb !important;
  padding-left: 10px;
}
.filter-button::v-deep .el-radio-button .el-radio-button__inner {
  border-radius: 6px !important;
  border: 1px solid rgb(245, 134, 106);
  color: rgb(245, 134, 106);
  background-color: rgb(254, 237, 226);
}
.filter-button::v-deep
  .el-radio-button__orig-radio:checked
  + .el-radio-button__inner {
  border: 1px solid rgb(245, 134, 106);
  color: white;
  background-color: rgb(245, 134, 106);
}
.wrapper-container {
  width: 1711px;
  margin: 0 auto;
}
.table-container {
  margin-top: 30px;

  .table-data {
    width: 100%;
    border: 0.8px solid #004ca7;
    border-radius: 9px;
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #004ca7;
  }
}

.save-button {
  width: 87px;
  height: 36px;
  line-height: 36px;
  background: #fff6ef;
  border: 1px solid #f3b815;
  border-radius: 6px;
  font-size: 18px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: #f3b815;
  text-align: center;
  margin: 82px auto;
}

.zuoyou {
  width: 200px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}
</style>
